package cn.hl.hm.controller;

import cn.hl.hm.constants.*;
import cn.hl.hm.dao.RouteVehiclePriceMapper;
import cn.hl.hm.dao.VehicleLengthMapper;
import cn.hl.hm.dao.VtVlMapper;
import cn.hl.hm.entity.*;
import cn.hl.hm.service.*;
import cn.hl.hm.util.*;
import cn.hl.hm.util.InfoCode;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
import com.vizhuo.utils.StringUtil;
import jxl.Sheet;
import jxl.Workbook;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import smsClient.TestSDKClient;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.FileInputStream;
import java.io.InputStream;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
/**
 * 
 * @author 大和
 * 订单
 *
 */
@Controller
@RequestMapping("/orderController")
public class OrderController {
	private static final Logger logger = LoggerFactory.getLogger(OrderController.class);
    @Autowired
    OrderService orderService;
    
    @Autowired
    VtVlMapper vtVlMapper;
    
    @Autowired
    VehicleLengthMapper vehicleLengthMapper;
    
    @Autowired
    UserService userService;
    @Autowired
    DriverService driverService;
    @Autowired
    BackstageOperationRecordService operationRecordService;
    @Autowired
	@Qualifier("pushToAppServiceImpl")
	private PushToAppIService pushToAppIService;
    
    @Autowired
    private BeanPicUtil beanPicUtil;
    
    @Autowired
    RouteVehiclePriceMapper routeVehiclePriceMapper;

//    @Autowired
//	private StDriverLogic stDriverLogic;

	@Autowired
	private DriverVehicleService driverVehicleService;
    
    /**
      * @Title: send  
      * @Description: 发送订单
      * @date: 2017年1月5日
      * @author: 大和
      * @param appId
      * @param order
	  * carId 需求车型id（会和上一参数校验） vehicle_type 表
	  * useTime 用车时间（yyyy-dd-MM）
	  * lineId 路线id route表
	  * senderPhone 发货人电话
	  * reciveverPhone 收货人电话
	  * senderPhone 发货人电话
	  * reciveverPhone 收货人电话
	  * source 1 运营 2 APP
	  * userAccount 登录人账号（电话）
	  * message  给司机留言
	  * operId  source为1 必填
	  * carLineId 车型-路线-价格表 route_vehicle_price表
	  * totalPriceStr 订单价格
	  * destAddress 目的地名称
	  * srcAddress 出发地名称
	  * lineName 线路名称，A-B
	  * giftPrice  补贴金额
	  * prepayPrice  预付金额
      * @param request
      * @param response
      * @return String 
      * @throws
     */
	@RequestMapping(value = "/send", method = RequestMethod.POST)
	public String send(
        String appId, 
        Order order,
        @RequestParam String source,
        Integer operId,
		HttpServletRequest request, HttpServletResponse response)  {
		logger.info("业务/订单管理---发送订单/发送订单---orderController/send");
		if(source.equals(SourceStatus.BACKGROUND.getStatus())&&operId==null){
			Result.ok(null, InfoCode.PARAM_ERROR, response);
			return null;
		}
		try{
			boolean checkSendParam = OrderUtil.checkSendParam(order);
			if(!checkSendParam){
				Result.ok(null, InfoCode.PARAM_ERROR, response);
				return null;
			}
			/*//用户有无未完成订单
			Order orderParam = new Order();
			orderParam.setSenderPhone(order.getSenderPhone());
			List<Order> selectOrder = orderService.selectOrder(orderParam);
			if(selectOrder!=null&&selectOrder.size()>0){
				for (Order order2 : selectOrder) {
					if(order2.getOrderStatus().equals(OrderStatus.TO_ACCEPT.getStatus())){
						//待派单
						Result.ok(null, InfoCode.USER_UNFINASH, response);
						return null;
					}else if(order2.getOrderStatus().equals(OrderStatus.TO_PAY.getStatus())){
						//待支付
						Result.ok(null, InfoCode.USER_UNFINASH, response);
						return null;
					}
				}
			}
			*/
			
			/*//TODO 根据车型和路线 返回当日价格
			RouteVehiclePrice ruteParam = new RouteVehiclePrice();
			ruteParam.setRouteId(order.getLineId());
			ruteParam.setVtVlId(order.getVtVlId());
			List<RouteVehiclePrice> todayPrice = orderService.selectRouteVehiclePrice(ruteParam);
			Route route = null;
			if(todayPrice!=null&&todayPrice.size()>0){
				 route = orderService.selectRoute(todayPrice.get(0).getRouteId());
				 if(route==null){
					 Result.ok(null, InfoCode.CAR_LINE_ERROR, response);
						return null; 
				 }
				 StringBuffer sb = new StringBuffer();
				 String lineName = sb.append(route.getStartPoint()).append("-").append(route.getEndPoint()).toString();
				 order.setLineName(lineName);
			}else {
				Result.ok(null, InfoCode.CAR_LINE_ERROR, response);
				return null;
			}
			
			Double totalmills = route.getRouteMileage();
			if(totalmills==null){
				Result.ok(null, InfoCode.CAR_LINE_ERROR, response);
				return null;
			}*/
			//是否注册用户
			User user = new User();
			user.setUserAccount(order.getSenderPhone());
			List<User> selectUser = userService.selectUser(user);
			if(selectUser!=null&&selectUser.size()>0){
				order.setSenderCompanyName(selectUser.get(0).getCompanyName());
				order.setUserId(selectUser.get(0).getId());
				//查询最优价格
				Map<String, String> map = new HashMap<>();
				map.put("startTime", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
				map.put("endTime", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
				map.put("userId", order.getUserId() + "");
				map.put("preferentialType", "2");
				//使用用户最大优惠的现金券
				Coupon cp = orderService.selectMostfavorable(map);
				if(cp!=null&&cp.getCash()!=null){
					order.setFavourPrice(new BigDecimal(cp.getCash()));//TODO 查询最大优惠
					order.setPersonalCode(cp.getCouponCode());
				}
			}
			//避免null
			if(order.getFavourPrice()==null){
				order.setFavourPrice(new BigDecimal(0));
			}
			//order.setCarLineId(todayPrice.get(0).getId());
			order.setCreateTime(new Date());
			order.setOrderCode(OrderUtil.getInstance().getOrderCode());
			
			
			order.setTotalPrice(new BigDecimal(order.getTotalPriceStr()));
			//支付金额=总金额-优惠金额
			order.setPayPrice(order.getTotalPrice().subtract(order.getFavourPrice()));
			order.setPlatformId(appId);
			//order.setTotalMileage(order.getTotalMileage());
			order.setOrderStatus(OrderStatus.TO_ACCEPT.getStatus());
			//order.setSrcAddress(route.getStartPoint());
			//order.setDestAddress(route.getEndPoint());
			//order.setSrcLonLat(route.getSrclonlat());
			//order.setDestLonLat(route.getDestlonlat());
			order.setUserAccount(order.getUserAccount());
			if(source.equals(SourceStatus.BACKGROUND.getStatus())&&operId!=null){
				order.setOperId(operId);
			}
			int add = orderService.add(order);
			if(add>0){
//				//添加用户常用路线
//				UserRoute param = new UserRoute();
//				param.setUserAccount(order.getSenderPhone());
//			//	param.setSrcAddress(route.getStartPoint());
//			//	param.setDestAddress(route.getEndPoint());
//				param.setSrcAddress(order.getSrcAddress());
//		     	param.setDestAddress(order.getDestAddress());
//				param.setCreateTime(new Date());
//				param.setOrderCode(order.getOrderCode());
//	    	//	param.setRouteVehiclePriceId(route.getId());
//				param.setRouteVehiclePriceId(order.getCarLineId());
//
//				userService.addUserRoute(param);
		     	//短信通知运营
				//TestSDKClient.testSendSMSE(Customers.phoneNumber, "【华凌叮当到】  用户" + order.getUserAccount()+"提交干线用车需求，请尽快处理。");
				
			/*	BigDecimal bd   =   new BigDecimal(order.getTotalMillsStr()).setScale(2,BigDecimal.ROUND_HALF_UP);
				order.setTotalMileage(bd);*/
				
				Result.ok(order, InfoCode.SUCCESS, response);
			    return null;
			}else {
				Result.ok(null, InfoCode.FAILURE, response);
				return null;
			}
		}catch(Exception e){
			e.printStackTrace();
			Result.ok(null, InfoCode.FAILURE, response);
			return null;
		}
		
	}
	
	/**
	  * @Title: give  
	  * @Description: 分配订单
	  * @date: 2017年1月5日
	  * @author: 大和
	  * @param orderCode
	  * @param driverAccount
	  * @param operId
	  * @param request
	  * @param response
	  * @return String 
	  * @throws
	 */
	@RequestMapping(value = "/give", method = RequestMethod.POST)
	public String give(
			@RequestParam String orderCode,
			@RequestParam String driverAccount,
			@RequestParam String plateNumber,
			@RequestParam Integer operId,
			HttpServletRequest request, HttpServletResponse response) {
		logger.info("业务/订单管理---分配订单/分配订单---orderController/give");
		try {
			Order orderParam = new Order();
			orderParam.setOrderCode(orderCode);
			List<Order> selectOrder = orderService.selectOrder(orderParam);
			// 处理订单  本体
			Order order = null;
			if (selectOrder != null && selectOrder.size() > 0) {
				order = selectOrder.get(0);
				if(!order.getOrderStatus().equals(OrderStatus.TO_ACCEPT.getStatus())){
					Result.ok(null, InfoCode.PARAM_ERROR, response);
					return null;
				}
				
				Driver driverParam = new Driver();
				driverParam.setDriverAccount(driverAccount);
				List<Driver> selectDriver = orderService.selectDriver(driverParam);
				if (selectDriver != null && selectDriver.size() > 0) {
				} else {
					Result.ok(null, InfoCode.PARAM_ERROR, response);
					return null;
				}
				Driver driver = selectDriver.get(0);
				String driverStatus = driver.getDriverStatus();
				String workStatus = driver.getWorkStatus();
				if(StringUtils.isBlank(driverStatus)||StringUtils.isBlank(workStatus)){
					Result.ok(null, InfoCode.PARAM_ERROR, response);
					return null;
				}
				List<DriverVehicle> driverVehicles = driverVehicleService.selectByIdAndNumberAndState(driver.getId(), plateNumber, null);
				if (driverVehicles==null ||driverVehicles.size()==0) {
					Result.ok(null, InfoCode.PARAM_ERROR, response);
					return null;
				}

				String passStatus = DriverStatus.PASS.getStatus();
				String freeStatus = DriverWorkStatus.FREE.getStatus();
				if (driverStatus.equals(passStatus)&& workStatus.equals(freeStatus)) {
					// 更改司机状态
					Driver driverUpParam = new Driver();
					driverUpParam.setId(driver.getId());
				//	driverUpParam.setDriverStatus(DriverWorkStatus.BUSY.getStatus());
					driverUpParam.setWorkStatus(DriverWorkStatus.BUSY.getStatus());

					int updateDriver = driverService.updateDriver(driverUpParam);

					if (updateDriver > 0) {
//						stDriverLogic.ayncVehicel(driverUpParam.getId());
						OrderRules rules = orderService.selectOrderRules();
						if (rules != null) {
							if(rules.getRoleId()!=null){
								Integer roleId = driver.getRoleId();
								if(roleId==null){
								}else {
									if(roleId.toString().equals(rules.getRoleId().toString())){
										BigDecimal infoFee = new BigDecimal(0);
										BigDecimal rewardFee = new BigDecimal(0);
										BigDecimal realPrice = order.getTotalPrice();
										if (rules.getStandard().equals("1")) {// 按比例收费
											infoFee = realPrice.multiply(rules.getInfoFeeRatio());
											rewardFee = realPrice.multiply(rules.getRewardRetio());
										} else if (rules.getStandard().equals("2")) {// 按固额收费
											infoFee = rules.getInfoFeeAmount();
											rewardFee = rules.getRewardAmount();
										} else {
										}
										order.setOrderRulesId(rules.getId());
										order.setInfoFee(infoFee);
										order.setRewardFee(rewardFee);
									}
								}
							}
						}
						order.setDriverId(driver.getId());
						order.setAcceptTime(new Date());
						order.setOrderStatus(OrderStatus.TO_PAY.getStatus());
						order.setOperId(operId);
						order.setDriverName(driver.getName());
						order.setDriverPhone(driver.getDriverAccount());
						order.setPlateNumber(plateNumber);
						int updateOrderById = orderService.updateOrderById(order);
						if (updateOrderById > 0) {
							// 注册用户推送、散人玩家发送短信
							String userAccount = order.getSenderPhone();
							User user = new User();
							user.setUserAccount(userAccount);
							List<User> selectUser = userService.selectUser(user);

							if (selectUser != null && selectUser.size() > 0) {
								// push
								User user2 = selectUser.get(0);
								if(user2!=null){
									if (StringUtils.isNotBlank(user2.getDeviceToken())) {
										Push push = new Push();
										push.setPtype(1);
										push.setPushoid(order.getOrderCode());
										push.setContext("司机" + driver.getName() + "（" + driver.getDriverLicense()
												+ "）已接单，请尽快支付订单金额"+order.getPayPrice()+"元");// 要发送的内容
										push.setDisplayType("notification");// message:
																			// 消息，通知：notification
										push.setOperationType(2);// 用户类型：1司机，2发货端
										push.setPushClient("consignerPushClient");// 使用的推送Client
																					// 是往发货端：consignerPushClient
																					// 或
																					// 司机端发送：driverPushClient。
										push.setPushType("listcast");// unicast：单播
																		// //
																		// listcast：列表
										push.setTitle("司机已接单"); // 发送的标题
										push.setTokenStr(new String[] { user2.getDeviceToken() }); // 要发送手机的token
										push.setOrderStatus(order.getOrderStatus());

										// ios & android推送公共调用方法
										pushToAppIService.pushCommon(push);
									}else {
//										TestSDKClient.testSendSMSE(userAccount, "【华凌叮当到】" + "司机" + driver.getName() + "（"
//												+ driver.getDriverLicense() + "）已接单，请尽快支付订单金额" + order.getPayPrice() + "元。");
										SendSmsRequest smsRequest = new SendSmsRequest();
										smsRequest.setTemplateParam("{\"driverName\":\""+driver.getName()+"\",\"payPrice\":\""+order.getPayPrice()+"\"}");
										TestSDKClient.sendSmsByAli("SMS_110375056",smsRequest,userAccount,"华凌叮当到");

									}
								}
								
							}
							
							//push to driver
						    Driver driverSelectParam = new Driver();
							driverSelectParam.setId(order.getDriverId());
							List<Driver> driverList = orderService.selectDriver(driverSelectParam);
							if(driverList!=null&&driverList.size()>0){
								Driver driverPush = driverList.get(0);
								
								if (StringUtils.isNotBlank(driverPush.getDeviceToken())) {
									Push push = new Push();
									push.setPtype(Push.PushTypeEnum.ORDERPUSH1.getId());
									push.setBizzType(Push.BizzTypeEnum.ORDER.getName());
									push.setPushoid(order.getOrderCode());
									push.setContext("您有新订单了，请到我的订单中查看。");// 要发送的内容
									push.setDisplayType("notification");// message: 消息，通知：notification
									push.setOperationType(1);// 用户类型：1司机，2发货端
									push.setPushClient("driverPushClient");// 使用的推送Client
																				// 是往发货端：consignerPushClient
																				// 或
																				// 司机端发送：driverPushClient。
									push.setPushType("listcast");// unicast：单播 // listcast：列表
									push.setTitle("您有新订单了，请尽快处理。"); // 发送的标题
									push.setTokenStr(new String[] { driverPush.getDeviceToken() }); // 要发送手机的token
									push.setOrderStatus(order.getOrderStatus());
									// ios & android推送公共调用方法
									pushToAppIService.pushCommon(push);
								}
								
							} 
							
							
							//操作记录
							operationRecordService.insertSelective(operId, null, "分配订单：【"+orderCode+"】");
							
						}

						Result.ok(null, InfoCode.SUCCESS, response);
						return null;
					} else {
						Result.ok(null, InfoCode.FAILURE, response);
						return null;
					}
				} else {
					Result.ok(null, InfoCode.DRIVER_ERROR, response);
					return null;
				}
			} else {
				Result.ok(null, InfoCode.PARAM_ERROR, response);
				return null;
			}
		} catch (Exception e) {
			e.printStackTrace();
			Result.ok(null, InfoCode.FAILURE, response);
			return null;
		}

	}
	
	/**
	  * @Title: cancle  
	  * @Description: 取消订单
	  * @date: 2017年1月5日
	  * @author: 大和
	  * @param appId
	  * @param orderCode
	  * @param cancleReason
	  * @param source
	  * @param operId
	  * @param request
	  * @param response
	  * @return String 
	  * @throws
	 */
	@RequestMapping(value = "/cancle", method = RequestMethod.POST)
	public String cancle(
        String appId, 
        @RequestParam String  orderCode,
        @RequestParam String  cancleReason,
        @RequestParam String  source,//1 运营后台 2app
        @RequestParam String  orderStatus,//订单状态
        Integer operId,
		HttpServletRequest request, HttpServletResponse response)  {
		logger.info("业务/订单管理---取消订单/取消订单---orderController/cancle");
		try{
			if(source.equals(SourceStatus.BACKGROUND.getStatus())&&operId==null){
				Result.ok(null, InfoCode.PARAM_ERROR, response);
				return null;
			}
			if(orderStatus.equals(OrderStatus.CANCLE.getStatus())||orderStatus.equals(OrderStatus.CLOSE.getStatus())){
				
			}else {
				Result.ok(null, InfoCode.PARAM_ERROR, response);
				return null;
			}
			Order orderParam = new Order();
			orderParam.setOrderCode(orderCode);
			
			
			List<Order> selectOrder = orderService.selectOrder(orderParam);
			if(selectOrder!=null&&selectOrder.size()>0){
				Order order = selectOrder.get(0);
				String orderStatus1 = order.getOrderStatus();
				
				//1 用戶(運營)取消條件： 未派發
				if(orderStatus.equals(OrderStatus.CANCLE.getStatus())){
					if(orderStatus1.equals(OrderStatus.TO_ACCEPT.getStatus())){
						
					}else {
						Result.ok(null, InfoCode.CANCLE_CONDITON, response);
						return null;
					}
					//2 運營關閉 close order 條件：用戶確認收貨之前  訂單狀體：1234
				}else if (orderStatus.equals(OrderStatus.CLOSE.getStatus())) {
					if(orderStatus1.equals(OrderStatus.TO_ACCEPT.getStatus())||orderStatus1.equals(OrderStatus.TO_PAY.getStatus())||orderStatus1.equals(OrderStatus.TO_ARRIVE.getStatus())||orderStatus1.equals(OrderStatus.TO_COMMENT.getStatus())){
						
					}else {
						Result.ok(null, InfoCode.CLOSE_CONDITON, response);
						return null;
					}
				}else {
					
				}
				
					order.setOrderStatus(orderStatus);
					order.setCancleReason(cancleReason);
					order.setCancleTime(new Date());
					if(SourceStatus.BACKGROUND.getStatus().equals(source)){
						order.setOperId(operId);
					}
					int updateOrderById = orderService.updateOrderById(order);
					if(updateOrderById>0){
						if(order.getDriverId()!=null){
							Driver driverUpdateParam = new Driver();
							driverUpdateParam.setId(order.getDriverId());
							driverUpdateParam.setWorkStatus(DriverWorkStatus.FREE.getStatus());
							int updateDriver = driverService.updateDriver(driverUpdateParam);
//							stDriverLogic.ayncVehicel(driverUpdateParam.getId());
							if(updateDriver>0){
								if(SourceStatus.BACKGROUND.getStatus().equals(source)){
									//操作记录
									operationRecordService.insertSelective(operId, null, "取消订单:【"+orderCode+"】");
								}
							}
						}
						
							//用户取消时，给运营发短信
							if(source.equals(SourceStatus.APP.getStatus())&&orderStatus.equals(OrderStatus.CANCLE.getStatus())) {
								//02 用户取消 通知运营  TODO 运营的电话
							//	TestSDKClient.testSendSMSE(Customers.phoneNumber, "【华凌叮当到】用户" + order.getUserAccount()+"取消了用车需求，订单已关闭。");
								SendSmsRequest smsRequest = new SendSmsRequest();
								smsRequest.setTemplateParam("{\"userAccount\":\""+order.getUserAccount()+"\"}");
							    TestSDKClient.sendSmsByAli("SMS_110390043",smsRequest,Customers.phoneNumber,"华凌叮当到");
							}else if(source.equals(SourceStatus.BACKGROUND.getStatus())&&orderStatus.equals(OrderStatus.CLOSE.getStatus())){

								//01运营关闭 通知司机和用户
								//注册用户推送、散人玩家发送短信
								//push to user
								String senderPhone = order.getSenderPhone();
								String userAccount = senderPhone;
								User userParam3 = new User();
								userParam3.setUserAccount(userAccount);
								List<User> selectUser = userService.selectUser(userParam3);
								if(selectUser!=null&&selectUser.size()>0){
									User user = selectUser.get(0);
									
									if (StringUtils.isNotBlank(user.getDeviceToken())) {
										Push push = new Push();
										push.setPtype(Push.PushTypeEnum.ORDERPUSH5.getId());
										push.setBizzType(Push.BizzTypeEnum.ORDER.getName());
										push.setContext("经协商，发往"+order.getDestAddress()+"的运单已关闭，请注意查看。");// 要发送的内容
										push.setDisplayType("notification");// message: 消息，通知：notification
										push.setOperationType(2);// 用户类型：1司机，2发货端
										push.setPushClient("consignerPushClient");// 使用的推送Client
																					// 是往发货端：consignerPushClient
																					// 或
																					// 司机端发送：driverPushClient。
										push.setPushType("listcast");// unicast：单播 // listcast：列表
										push.setTitle("取消订单"); // 发送的标题
										push.setTokenStr(new String[] { user.getDeviceToken() }); // 要发送手机的token
										push.setPushoid(order.getOrderCode());

										// ios & android推送公共调用方法
										pushToAppIService.pushCommon(push);
										
									}
								}
								//push to driver
							    Driver driverSelectParam = new Driver();
								driverSelectParam.setId(order.getDriverId());
								List<Driver> driverList = orderService.selectDriver(driverSelectParam);
								if(driverList!=null&&driverList.size()>0){
									Driver driver = driverList.get(0);
									
									if (StringUtils.isNotBlank(driver.getDeviceToken())) {
										Push push = new Push();
										push.setPtype(Push.PushTypeEnum.ORDERPUSH5.getId());
										push.setBizzType(Push.BizzTypeEnum.ORDER.getName());
										push.setPushoid(order.getOrderCode());

										String senderName = order.getSenderName();
										if(StringUtils.isBlank(senderName)){
											senderName = "";
										}else {
											senderName = order.getSenderPhone();
										}
										push.setContext("经双方协商，用户"+senderName+"的用车订单已关闭。");// 要发送的内容

										/*if(order.getSenderName()==null){
											push.setContext("经双方协商，用户"+order.getSenderPhone()+"的用车订单已关闭。");// 要发送的内容
										}else{
											push.setContext("经双方协商，用户"+order.getSenderName()+"的用车订单已关闭。");// 要发送的内容
										}
										*/
										

										push.setDisplayType("notification");// message: 消息，通知：notification
										push.setOperationType(1);// 用户类型：1司机，2发货端
										push.setPushClient("driverPushClient");// 使用的推送Client
																					// 是往发货端：consignerPushClient
																					// 或
																					// 司机端发送：driverPushClient。
										push.setPushType("listcast");// unicast：单播 // listcast：列表
										push.setTitle("取消订单"); // 发送的标题
										push.setTokenStr(new String[] { driver.getDeviceToken() }); // 要发送手机的token
										// ios & android推送公共调用方法
										pushToAppIService.pushCommon(push);
									}
									
								} 
								
							
							}
							
							Result.ok(null, InfoCode.SUCCESS, response);
							return null;
					}else {
						Result.ok(null, InfoCode.FAILURE, response);
						return null;
					}
			}else {
				Result.ok(null, InfoCode.PARAM_ERROR, response);
				return null;
			}
		}catch(Exception e){
			e.printStackTrace();
			Result.ok(null, InfoCode.FAILURE, response);
			return null;
		}
		
	}

	/**
	  * @Title: myOrderList  
	  * @Description: 订单列表
	  * @date: 2017年1月5日
	  * @author: 大和
	  * @param userAccount
	  * @param pageId
	  * @param pageCount
	  * @param request
	  * @param response
	  * @return String 
	  * @throws
	 */
	@RequestMapping(value = "/myOrderList", method = RequestMethod.POST)
	public String myOrderList(
       	Order order,
       	Integer operType,
        @RequestParam Integer pageId,
        @RequestParam Integer pageCount,
		HttpServletRequest request, 
		HttpServletResponse response)  {
		logger.info("业务/订单业务/司机管理---订单信息（列表/详情）/司机订单详情/接单记录列表---orderController/myOrderList");
		try{
			AppPager handle = AppPager.handle(pageId, pageCount);
			order.setPageId(handle.getPageId());
			order.setPageCount(handle.getPageCount());
			if(StringUtil.isNotBlank(order.getOrderStatus())){
				String orderStatus = order.getOrderStatus().trim();
				if(orderStatus.equals("\"\"")){
					order.setOrderStatus(null);
				}
			}
			List<Order> result  = new  ArrayList<>();
			order.setIsQueryList(true);
			List<Order> selectOrder = orderService.selectOrder(order);
			if(selectOrder!=null&&selectOrder.size()>0){
				for (Order o : selectOrder) {
					Order order2 = beanPicUtil.modifyUrl(o);
					if(order.getOrderRulesId()!=null){
						OrderRules rules = orderService.selectOrderRules();
						order2.setOrderRules(rules);
					}
					order2.setSigns(null);//敏感
					
					//路线
					Integer lineId = order2.getLineId();
					if(lineId!=null){
						Route selectRoute = orderService.selectRoute(lineId);
						order2.setRoute(selectRoute);
					}
					Integer carLineId = order2.getCarLineId();


					if(carLineId!=null){
						//路线车型当日价格
						RouteVehiclePrice roPrice = new RouteVehiclePrice();
						roPrice.setId(carLineId);
						/*if(operType!=null){
							roPrice.setOperType(operType);
						}*/
						RouteVehiclePrice selectRouteVehiclePrice = routeVehiclePriceMapper.selectByPrimaryKey(carLineId);
							order2.setRouteVehiclePrice(selectRouteVehiclePrice);
							if(selectRouteVehiclePrice!=null){
								//车辆长度
								Integer vtVlId = selectRouteVehiclePrice.getVtVlId();
								if(vtVlId!=null){
									DriverVehicle driverVehicle= driverVehicleService.selectByPrimaryKey(vtVlId);
//									VtVl selectByPrimaryKey = vtVlMapper.selectByPrimaryKey(vtVlId);
									if(driverVehicle!=null){
										VehicleLength selectByPrimaryKey2 = vehicleLengthMapper.selectByPrimaryKey(driverVehicle.getVehicleLengthId());
										order2.setVehicleLength(selectByPrimaryKey2);

									}
								}
							}
							
					}
					Integer carId = order2.getCarId();
					if(carId!=null){
						//车型
						VehicleType selectCarType = orderService.selectCarType(carId);
						order2.setVehicleType(selectCarType);
					}
					String senderPhone = order2.getSenderPhone();
					if(StringUtils.isNotBlank(senderPhone)){
						//给user
						User qUser = new User();
						qUser.setUserAccount(senderPhone);
						List<User> selectUser = userService.selectUser(qUser);
						if(selectUser!=null&&selectUser.size()>0){
							User user = selectUser.get(0);
							User modifyUrl = beanPicUtil.modifyUrl(user);
							Order querySuccess =new Order();
							querySuccess.setSenderPhone( user.getUserAccount());
							Order orderSuccess = orderService.selectUserSuccess(querySuccess);
							modifyUrl.setSuccessOrder(orderSuccess.getId());
							modifyUrl.setSuccessOrderPrice(orderSuccess.getTotalPrice());
							order2.setUser(modifyUrl);
						}
					}
					//给driver
					Driver qDriver = new Driver();
					Integer driverId = order2.getDriverId();
					if(driverId!=null){
						qDriver.setId(driverId);
						List<Driver> selectDriver = driverService.selectDriver(qDriver);
						if(selectDriver!=null&&selectDriver.size()>0){
							Driver driver = selectDriver.get(0);
							Driver modifyUrl = beanPicUtil.modifyUrl(driver);
							order2.setDriver(modifyUrl);
						}
					}
					
					//给 订单 扣费规则
					Integer orderRulesId = order2.getOrderRulesId();
					if(orderRulesId!=null){
						OrderRules selectOrderRulesById = orderService.selectOrderRulesById(orderRulesId);
						order2.setOrderRules(selectOrderRulesById);
					}
					if(order2.getId()!=null){
						OrderReview orderReview = new OrderReview();
						orderReview.setOrderId(order2.getId());
						List<OrderReview> selectOrderReview = orderService.selectOrderReview(orderReview);
						if(selectOrderReview!=null&&selectOrderReview.size()>0){
							OrderReview orderReview2 = selectOrderReview.get(0);
							order2.setOrderReview(orderReview2);
						}
					}
					
					//给评论
					OrderReview reviewParam =new OrderReview();
					reviewParam.setOrderId(order2.getId());
					List<OrderReview> selectOrderReview = orderService.selectOrderReview(reviewParam);
					if(selectOrderReview!=null&&selectOrderReview.size()>0){
						order2.setOrderReview(selectOrderReview.get(0));

					}
					
					result.add(order2);
				}
			
			}
			
			Result.ok(result, InfoCode.SUCCESS, response);
			return null;
			
		}catch(Exception e){
			e.printStackTrace();
			Result.ok(null, InfoCode.FAILURE, response);
			return null;

		}
		
	}
	
	/**
	  * @Title: myOrderList  
	  * @Description: 订单列表
	  * @date: 2017年1月5日
	  * @author: 大和
	  * @param userAccount
	  * @param pageId
	  * @param pageCount
	  * @param request
	  * @param response
	  * @return String 
	  * @throws
	 */
	@RequestMapping(value = "/myOrderListH5", method = RequestMethod.POST)
	public String myOrderListH5(
      	Order order,
      	Integer operType,
       @RequestParam Integer pageId,
       @RequestParam Integer pageCount,
		HttpServletRequest request, 
		HttpServletResponse response)  {
		logger.info("订单管理---订单信息(列表/详情)---orderController/myOrderListH5");
		try{
			AppPager handle = AppPager.handle(pageId, pageCount);
			order.setPageId(handle.getPageId());
			order.setPageCount(handle.getPageCount());
			
			if(StringUtil.isNotBlank(order.getOrderStatus())){
				String orderStatus = order.getOrderStatus().trim();
				if(orderStatus.equals("\"\"")){
					order.setOrderStatus(null);
				}
			}
//			List<Order> result  = new  ArrayList<>();
			List<Order> selectOrder = orderService.selectOrderForH5(order);
//			if(selectOrder!=null&&selectOrder.size()>0){
//				for (Order o : selectOrder) {
//					Order order2 = beanPicUtil.modifyUrl(o);
//				 
//					
//					//路线
//					Integer lineId = order2.getLineId();
//					if(lineId!=null){
//						Route selectRoute = orderService.selectRoute(lineId);
//						order2.setRoute(selectRoute);
//					}
//					Integer carLineId = order2.getCarLineId();
//					if(carLineId!=null){
//						//路线车型当日价格
//						RouteVehiclePrice roPrice = new RouteVehiclePrice();
//						roPrice.setId(carLineId);
//						RouteVehiclePrice selectRouteVehiclePrice = routeVehiclePriceMapper.selectByPrimaryKey(carLineId);
//							order2.setRouteVehiclePrice(selectRouteVehiclePrice);
//							if(selectRouteVehiclePrice!=null){
//								//车辆长度
//								Integer vtVlId = selectRouteVehiclePrice.getVtVlId();
//								if(vtVlId!=null){
//									VtVl selectByPrimaryKey = vtVlMapper.selectByPrimaryKey(vtVlId);
//									if(selectByPrimaryKey!=null){
//										VehicleLength selectByPrimaryKey2 = vehicleLengthMapper.selectByPrimaryKey(selectByPrimaryKey.getVehicleLengthId());
//										order2.setVehicleLength(selectByPrimaryKey2);
//									}
//								}
//							}
//							
//					}
//					Integer carId = order2.getCarId();
//					if(carId!=null){
//						//车型
//						VehicleType selectCarType = orderService.selectCarType(carId);
//						order2.setVehicleType(selectCarType);
//					}
//					result.add(order2);
//				}
//			
//			}
			
			Result.ok(selectOrder, InfoCode.SUCCESS, response);
			return null;

			
			
			
		}catch(Exception e){
			e.printStackTrace();
			Result.ok(null, InfoCode.FAILURE, response);
			return null;

		}
		
	}
	
	
	/**
	 * 
	  * @Title: comment  
	  * @Description: 用户评价订单
	  * @date: 2017年1月5日
	  * @author: 大和
	  * @param appId
	  * @param orderCode
	  * @param rank
	  * @param comment
	  * @param operId
	  * @param request
	  * @param response
	  * @return String 
	  * @throws
	 */
	@RequestMapping(value = "/comment", method = RequestMethod.POST)
	public String comment(
        String appId, 
        @RequestParam String  orderCode,
        @RequestParam Integer  rank,
        @RequestParam String  comment,
        Integer operId,
		HttpServletRequest request, HttpServletResponse response)  {
		logger.info("业务---评价订单---orderController/comment");
		Order orderParam = new Order();
		orderParam.setOrderCode(orderCode);
		List<Order> selectOrder = orderService.selectOrder(orderParam);
		if(selectOrder!=null&&selectOrder.size()>0){
			Order order = selectOrder.get(0);
			OrderReview reviewParam =new OrderReview();
			reviewParam.setOrderId(order.getId());
			List<OrderReview> selectOrderReview = orderService.selectOrderReview(reviewParam);
			if(selectOrderReview!=null&&selectOrderReview.size()>0){
				Result.ok(null, InfoCode.FAILURE, response);
				return null;
			}else {
				User userParam = new User();
				userParam.setUserAccount(order.getSenderPhone());
				List<User> selectUser = userService.selectUser(userParam);
				if(selectUser!=null&&selectUser.size()>0){
					OrderReview review =new OrderReview();
					review.setOrderId(order.getId());
					review.setRank(rank);
					User sendUser = selectUser.get(0);
					review.setSenderId(sendUser.getId());
					review.setDriverId(order.getDriverId());
					review.setContent(comment);
					review.setCreateTime(new Date());
					int addOrderReview = orderService.addOrderReview(review);
					

					if(addOrderReview>0){
						Order orderParam2 =new Order();
						orderParam2.setOrderStatus(OrderStatus.TO_RECIVE_USER_MONEY.getStatus());
						orderParam2.setCommentTime(new Date());
						orderParam2.setId(order.getId());
						orderParam2.setPlatformId(appId);
						int updateOrderById = orderService.updateOrderById(orderParam2);
						if(updateOrderById>0){
							Driver driverParam = new Driver();
							driverParam.setId(order.getDriverId());
							List<Driver> driverList = orderService.selectDriver(driverParam);
							if(driverList!=null&&driverList.size()>0){
								Driver driver = driverList.get(0);
								//推送
								if (StringUtils.isNotBlank(driver.getDeviceToken())) {
									Push push = new Push();
									push.setPtype(1);// 推荐场景类型，1 订单 2 H5活动 3 信息变更 4 奖励  

									push.setPushoid(order.getOrderCode());
									push.setContext("用户"+sendUser.getUserAccount()+"评价了您的服务。");// 要发送的内容
									push.setDisplayType("notification");// message: 消息，通知：notification
									push.setOperationType(1);// 用户类型：1司机，2发货端
									push.setPushClient("driverPushClient");// 使用的推送Client
																				// 是往发货端：consignerPushClient
																				// 或
																				// 司机端发送：driverPushClient。
									push.setPushType("listcast");// unicast：单播 // listcast：列表
									push.setTitle("评价订单成功"); // 发送的标题
									push.setTokenStr(new String[] { driver.getDeviceToken() }); // 要发送手机的token
									// ios & android推送公共调用方法
									pushToAppIService.pushCommon(push);
									Result.ok(null, InfoCode.SUCCESS, response);
									return null;
								}
								Result.ok(null, InfoCode.SUCCESS, response);
								return null;
							}
							Result.ok(null, InfoCode.SUCCESS, response);
							return null;
						}else {
							Result.ok(null, InfoCode.FAILURE, response);
							return null;
						}
					}else {
						Result.ok(null, InfoCode.FAILURE, response);
						return null;
					}
				}else {
					Result.ok(null, InfoCode.FAILURE, response);
					return null;
				}
			}
		} else {

			Result.ok(null, InfoCode.FAILURE, response);
			return null;

		}
	}
	/**
	 * 
	  * @Title: ensure  
	  * @Description: 用户确认收货
	  * @date: 2017年1月5日
	  * @author: 大和
	  * @param appId
	  * @param orderCode
	  * @param password
	  * @param source
	  * @param operId
	  * @param request
	  * @param response
	  * @return String 
	  * @throws
	 */
	@RequestMapping(value = "/ensure", method = RequestMethod.POST)
	public String ensure(
        String appId, 
        @RequestParam String  orderCode,
        @RequestParam String   password,
        @RequestParam String source, //1 平台 2 APP
        Integer operId,
		HttpServletRequest request, HttpServletResponse response)  {
		logger.info("业务---用户确认收货---orderController/ensure");
		if(source.equals(SourceStatus.BACKGROUND.getStatus())&&operId==null){
			Result.ok(null, InfoCode.PARAM_ERROR, response);
			return null;
		}
		Order orderParam = new Order();
		orderParam.setOrderCode(orderCode);
		List<Order> selectOrder = orderService.selectOrder(orderParam);
		if(selectOrder!=null&&selectOrder.size()>0){
		 	Order order = selectOrder.get(0);
			
			User userParam = new User();
			userParam.setUserAccount(order.getSenderPhone());
			userParam.setPassword(password);
			List<User> selectUser = userService.selectUser(userParam);
			if(selectUser!=null&&selectUser.size()>0){
				String orderStatus = order.getOrderStatus();
				if(orderStatus.equals(OrderStatus.TO_ARRIVE.getStatus())){
					Order orderParam2 =new Order();
					orderParam2.setOrderStatus(OrderStatus.TO_COMMENT.getStatus());
					orderParam2.setId(order.getId());
					orderParam2.setUserEnsureTime(new Date());
					if(operId!=null&&source.equals(SourceStatus.BACKGROUND.getStatus())){
						orderParam2.setPlatformId(appId);
					}
					int updateOrderById = orderService.updateOrderById(orderParam2);
					if(updateOrderById>0){
						Driver driverUpdateParam = new Driver();
						driverUpdateParam.setId(order.getDriverId());
						driverUpdateParam.setWorkStatus(DriverWorkStatus.FREE.getStatus());
						int updateDriver = driverService.updateDriver(driverUpdateParam);
//						stDriverLogic.ayncVehicel(driverUpdateParam.getId());
						if(updateDriver>0){
							if(SourceStatus.BACKGROUND.getStatus().equals(source)){
								//操作记录
								operationRecordService.insertSelective(operId, null, "确认送达:【"+orderCode+"】");
							
							
							}
							Result.ok(null, InfoCode.SUCCESS, response);
							return null;
						}else {
							Result.ok(null, InfoCode.FAILURE, response);
							return null;
						}
					}else {
						Result.ok(null, InfoCode.FAILURE, response);
						return null;

					}
				}else {
					Result.ok(null, InfoCode.FAILURE, response);
					return null;
				}
			}else {
				Result.ok(null, InfoCode.AUTH_ERROR, response);
				return null;
			}
		} else {

			Result.ok(null, InfoCode.FAILURE, response);
			return null;

		}
		
	}
	
	/**
	  * @Title: orderInfo  
	  * @Description: 订单详情
	  * @date: 2017年1月5日
	  * @author: 大和
	  * @param orderCode
	  * @param request
	  * @param response
	  * @return String 
	  * @throws
	 */
	@RequestMapping(value = "/orderPrice", method = RequestMethod.POST)
	public String orderPrice(
       @RequestParam String  orderCode,
       @RequestParam BigDecimal payPrice,
		HttpServletRequest request, HttpServletResponse response)  {
		logger.info("资金---获取支付价格---orderController/orderPrice");
		try{
			Order orderParam = new Order();
			orderParam.setOrderCode(orderCode);
			//orderParam.setPayPrice(payPrice);
			List<Order> selectOrder = orderService.selectOrder(orderParam);
			
			if(selectOrder!=null&&selectOrder.size()>0){
				Order order = selectOrder.get(0);
				Result.ok(order.getPayPrice(), InfoCode.SUCCESS, response);
				return null;

			}else {
				Result.ok(null, InfoCode.FAILURE, response);
				return null;
			}
			
		}catch(Exception e){
			e.printStackTrace();
			Result.ok(null, InfoCode.FAILURE, response);
			return null;
		}
		
	}
	
	@RequestMapping(value = "/driverCommentList", method = RequestMethod.POST)
	public String driverCommentList(
       @RequestParam Integer driverId  ,
       @RequestParam Integer pageId,
       @RequestParam Integer pageCount,
       
       HttpServletRequest request,HttpServletResponse response) {
	   logger.info("个人中心---司机评价列表---orderController/driverCommentList");
		try {
			OrderReview or = new OrderReview();
			AppPager handle = AppPager.handle(pageId, pageCount);
			or.setPageId(handle.getPageId());
			or.setPageCount(handle.getPageCount());
			or.setDriverId(driverId);
			List<OrderReview> selectOrderReview = orderService.selectOrderReview(or);

			Result.ok(selectOrderReview, InfoCode.SUCCESS, response);
			return null;

		} catch (Exception e) {
			e.printStackTrace();
			Result.ok(null, InfoCode.FAILURE, response);
			return null;
		}

	}
	
	
	
	
	@RequestMapping(value = "/updateOrder", method = RequestMethod.POST)
	public String updateOrder(
	   Order order,
       @RequestParam Integer  operId,//order里有这个属性 只是让其必填
       @RequestParam String type,// 1 修改时间节点 2修改基本信息
			HttpServletRequest request, HttpServletResponse response) {
		logger.info("业务/订单管理---更新订单信息/修改订单（节点/发单信息）---orderController/updateOrder");

		try {
			if (order == null || order.getId() == null) {
				Result.ok(null, InfoCode.PARAM_ERROR, response);
				return null;
			}
			Order orderResult = null;
			Order orderParam = new Order();
			orderParam.setId(order.getId());
			List<Order> selectOrder = orderService.selectOrder(orderParam);
			if (selectOrder != null && selectOrder.size() > 0) {
				orderResult = selectOrder.get(0);

			} else {
				Result.ok(null, InfoCode.FAILURE, response);
				return null;
			}
			if (type.equals("1")) {
				Order updateParam = new Order();
				if (StringUtils.isBlank(order.getOrderStatus())) {
					Result.ok(null, InfoCode.ORDER_STATUS_EMPTY_ERROR, response);
					return null;
				}
				updateParam.setId(order.getId());
				updateParam.setOrderStatus(order.getOrderStatus());
				updateParam.setOperId(operId);
				if(order.getOrderStatus().equals("4")){
					updateParam.setUserEnsureTime(new Date());
				}
				if(order.getOrderStatus().equals("4")||order.getOrderStatus().equals("3")){
					//后台修改订单 已支付 3 /已完成4 标记支付时间  支付方式
					updateParam.setPayType(PayMethod.CASH.getCode());
					updateParam.setPayTime(new Date());
				}
				
				int updateOrderById = orderService.updateOrderById(updateParam);
				if (updateOrderById > 0) {
					//送达后 更改司机状态为空闲
					if(order.getOrderStatus().equals("21")||order.getOrderStatus().equals("4")){
						Driver driverUpdateParam = new Driver();
						driverUpdateParam.setId(orderResult.getDriverId());
						driverUpdateParam.setWorkStatus(DriverWorkStatus.FREE.getStatus());
						driverService.updateDriver(driverUpdateParam);
//						stDriverLogic.ayncVehicel(driverUpdateParam.getId());
					}
					
					operationRecordService.insertSelective(operId, null, "更改订单:【"+orderResult.getOrderCode()+"】  orderStatus："+order.getOrderStatus());
					Result.ok(null, InfoCode.SUCCESS, response);
					return null;
				} else {
					Result.ok(null, InfoCode.FAILURE, response);
					return null;
				}
					
			} else if (type.equals("2")) {
					Order orderUpdate = null;
					String orderPics = order.getOrderPics();
					if(StringUtils.isNotBlank(orderPics)){
						order.setId(orderResult.getId());//
						orderUpdate = beanPicUtil.cutUrl(order);
						
					}else {
						order.setId(orderResult.getId());//
						orderUpdate = order;
					}
					
					int updateOrderById = orderService.updateOrderById(orderUpdate);
					if (updateOrderById > 0) {
						//操作记录
						operationRecordService.insertSelective(operId, null, "更改订单:【"+orderResult.getOrderCode()+"】");
						Result.ok(null, InfoCode.SUCCESS, response);
						return null;
					} else {
						Result.ok(null, InfoCode.FAILURE, response);
						return null;
					}
						
				
			} else {
				Result.ok(null, InfoCode.FAILURE, response);
				return null;
			}

		} catch (Exception e) {
			e.printStackTrace();
			Result.ok(null, InfoCode.FAILURE, response);
			return null;
		}

	}
	
	/**
	  * @Title: addOrderRule  
	  * @Description: 添加收费规则
	  * @date: 2017年1月10日
	  * @author:大和
	  * @param infoFeeRatio
	  * @param rewardRetio
	  * @param roleId
	  * @param request
	  * @param orderRules
	  * @param response
	  * @return String 
	  * @throws
	 */
	@RequestMapping(value = "/addOrderRule", method = RequestMethod.POST)
	@ResponseBody
	public String addOrderRule(@RequestParam("infoFeeRatio") String infoFeeRatio,
			@RequestParam("rewardRetio") String rewardRetio, 
		   @RequestParam("roleId") String roleId, HttpServletRequest request,
		   OrderRules orderRules,
			HttpServletResponse response) {
		logger.info("订单分成与奖励---添加规则/修改规则---orderController/addOrderRule");
		try {
			orderService.addOrderOrderRules(orderRules);
			Result.ok(1, InfoCode.SUCCESS, response);
			return null;
		} catch (Exception e) {
			Result.ok(null, InfoCode.FAILURE, response);
			e.printStackTrace();
			return null;
		}
	} 
 
    
    
    
	@RequestMapping(value = "/importOrder", method = RequestMethod.POST)
	@ResponseBody
	public String importOrder( HttpServletRequest request,
		  
			HttpServletResponse response) {
//		 List<Order> list=new ArrayList<Order>();
	        try {
	        	  InputStream is = new FileInputStream("c://work//11.xls");   
	        	  
	              Workbook rwb = Workbook.getWorkbook(is);   
//	            Workbook rwb=Workbook.getWorkbook(new File("c://work//new.xls"));
	            Sheet rs=rwb.getSheet(0); 
	            int clos=rs.getColumns(); 
	            int rows=rs.getRows(); 
	            for (int i = 0; i < rows; i++) {
	                for (int j = 0; j < clos; j++) {
	                	
	                	Order order = new Order();
	                    //第一个是列数，第二个是行数 默认最左边编号也算一列 所以这里得j++
	                    order.setLineId(Integer.parseInt(rs.getCell(j++, i).getContents()));// 路线ID
	                    order.setSenderCompanyName(rs.getCell(j++, i).getContents());
	                    order.setGoodsName(   rs.getCell(j++, i).getContents());
	                    order.setSenderName(               rs.getCell(j++, i).getContents());
	                    order.   setSenderPhone(              rs.getCell(j++, i).getContents());
	                   
	                    order.        setReciveverPhone   (  rs.getCell(j++, i).getContents());
						                
//						                    order.setTotalPrice( new BigDecimal(rs.getCell(j++, i).getContents()));
						                 
						                    order. setDriverName(               rs.getCell(j++, i).getContents());
						                    order.          setDriverPhone(       rs.getCell(j++, i).getContents());
						                    order.            setCarId(Integer.parseInt(    rs.getCell(j++, i).getContents()));
						                    order.          setSrcAddress(       rs.getCell(j++, i).getContents());
						                    order.          setDestAddress(       rs.getCell(j++, i).getContents());
						             
//	                    list.add(order);
						                	order.setOrderCode(OrderUtil.getInstance().getOrderCode());
//						        			order.setPlatformId(appId);
						                    order.setOrderStatus("7");
						                    
						                    
						                    Driver driverParam = new Driver();
						        			driverParam.setDriverAccount(order.getDriverPhone());
						        			List<Driver> selectDriver = orderService.selectDriver(driverParam);
						        			if (selectDriver != null && selectDriver.size() > 0) {
						        			} else {
//						        				Result.ok(null, InfoCode.DRIVER_EXIXTS_ERROR, response);
//						        				return null;
						        			}
						        			Driver driver = selectDriver.get(0);
						        			if(driver.getId()!=null){
						        			order.setDriverId(driver.getId());
						        			}
//						        			order.setDriverName(driver.getName());
//						        			order.setDriverPhone(driver.getDriverAccount());
						        			
						        			//是否注册用户
						        			User user = new User();
						        			user.setUserAccount(order.getSenderPhone());
						        				order.setFavourPrice(new BigDecimal(0));
						        			order.setCreateTime(order.getUseTime());
						        			order.setOrderCode(OrderUtil.getInstance().getOrderCode());
						        			
//						        			order.setTotalPrice(new BigDecimal(order.getTotalPriceStr()));
						        			order.setPayPrice(order.getTotalPrice());
						        			
						        			order.setPlatformId("_2017-05-05手动导入_");
						        			order.setTotalMileage(order.getTotalMileage());
						        			order.setOrderStatus(OrderStatus.FINISH.getStatus());
						        			order.setUserAccount(order.getSenderPhone());
						        			order.setSenderPhone(order.getSenderPhone());
						        			order.setPayType("1");
						        			if(order.getSrcAddress().equals("乌市")&&order.getDestAddress().equals("哈密")){
						        				order.setLineId(26);
						        				order.setTotalMileage(new BigDecimal(3.7));
						        				order.setLineName("乌市-哈密");
						        			}else if  (order.getSrcAddress().equals("乌市")&&order.getDestAddress().equals("阿克苏")){
						        				order.setLineId(27);
						        				order.setTotalMileage(new BigDecimal(1008.6));
						        				order.setLineName("乌市-阿克苏");
						        			}else if  (order.getSrcAddress().equals("乌市")&&order.getDestAddress().equals("喀什")){
						        				order.setLineId(28);
						        				order.setTotalMileage(new BigDecimal(15.6));
						        				order.setLineName("乌市-喀什");
						        			}else if  (order.getSrcAddress().equals("乌市")&&order.getDestAddress().equals("莎车")){
						        				order.setLineId(29);
						        				order.setTotalMileage(new BigDecimal(1458.4));
						        				order.setLineName("乌市-莎车");
						        			}else if  (order.getSrcAddress().equals("乌市")&&order.getDestAddress().equals("伊犁")){
						        				order.setLineId(30);
						        				order.setTotalMileage(new BigDecimal(1.9));
						        				order.setLineName("乌市-伊犁");
						        			}
     
						                    
						                    
						                    
						                    
						                    
						                    orderService.add(order);
	                }
	            }
	            
	            
	            
	            
	            
	        } catch (Exception e) {
	            // TODO Auto-generated catch block
	            e.printStackTrace();
	        } 
	        return null;
	} 
}
